package entity;

import java.awt.Component;
import javax.swing.Icon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;

public class TreeRenderer extends DefaultTreeCellRenderer 
{
    Icon databaseIcon;
    Icon tableIcon;
    Icon columnIcon;

    public TreeRenderer(Icon databaseIcon,Icon tableIcon,Icon columnIcon) 
    {
        this.databaseIcon = databaseIcon;
        this.tableIcon = tableIcon;
        this.columnIcon = columnIcon;
    }

    public Component getTreeCellRendererComponent(
                        JTree tree,
                        Object value,
                        boolean sel,
                        boolean expanded,
                        boolean leaf,
                        int row,
                        boolean hasFocus) 
    {
        super.getTreeCellRendererComponent( tree, value, sel, expanded, leaf, row, hasFocus);
        DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
        int level = node.getLevel();
        switch (level)
        {
        	case 1:
        		setIcon(databaseIcon);
        		break;
        	case 2:
        		setIcon(tableIcon);
        		break;
        	case 3:
        		setIcon(columnIcon);
        		break;
        }

        return this;
    }
}
